/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.google.common.collect.ImmutableSet;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.OperationContext;
/*    */ import com.zimbra.cs.mailbox.Tag;
/*    */ import com.zimbra.cs.mailbox.util.TagUtil;
/*    */ import com.zimbra.cs.service.util.ItemId;
/*    */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.mail.type.RetentionPolicy;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class TagAction
/*    */   extends ItemAction
/*    */ {
/*    */   public static final String OP_RETENTION_POLICY = "retentionpolicy";
/* 43 */   private static final Set<String> TAG_ACTIONS = ImmutableSet.of("read", "color", "delete", "rename", "update", "retentionpolicy", new String[0]);
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*    */   {
/* 47 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 48 */     Mailbox mbox = getRequestedMailbox(zsc);
/* 49 */     OperationContext octxt = getOperationContext(zsc, context);
/*    */     
/* 51 */     Element action = request.getElement("action");
/* 52 */     String opAttr = action.getAttribute("op").toLowerCase();
/* 53 */     String operation = getOperation(opAttr);
/*    */     
/* 55 */     if ((operation.equals("tag")) || (operation.equals("flag"))) {
/* 56 */       throw ServiceException.INVALID_REQUEST("cannot tag/flag a tag", null);
/*    */     }
/* 58 */     if (!TAG_ACTIONS.contains(operation)) {
/* 59 */       throw ServiceException.INVALID_REQUEST("invalid operation on tag: " + opAttr, null);
/*    */     }
/*    */     
/* 62 */     String tn = action.getAttribute("tn", null);
/* 63 */     if (tn != null)
/*    */     {
/* 65 */       StringBuilder tagids = new StringBuilder();
/* 66 */       for (String name : TagUtil.decodeTags(tn)) {
/* 67 */         tagids.append(tagids.length() == 0 ? "" : ",").append(mbox.getTagByName(octxt, name).getId());
/*    */       }
/* 69 */       action.addAttribute("id", tagids.toString());
/*    */     }
/*    */     String successes;
/*    */     String successes;
/* 73 */     if (operation.equals("retentionpolicy")) {
/* 74 */       ItemId iid = new ItemId(action.getAttribute("id"), zsc);
/* 75 */       RetentionPolicy rp = new RetentionPolicy(action.getElement("retentionPolicy"));
/* 76 */       mbox.setRetentionPolicy(octxt, iid.getId(), MailItem.Type.TAG, rp);
/* 77 */       successes = new ItemIdFormatter(zsc).formatItemId(iid);
/*    */     } else {
/* 79 */       successes = handleCommon(context, request, opAttr, MailItem.Type.TAG);
/*    */     }
/*    */     
/* 82 */     Element response = zsc.createElement(MailConstants.TAG_ACTION_RESPONSE);
/* 83 */     Element result = response.addUniqueElement("action");
/* 84 */     result.addAttribute("id", successes);
/* 85 */     result.addAttribute("tn", tn);
/* 86 */     result.addAttribute("op", opAttr);
/* 87 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/TagAction.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */